package com.project.frba.bi.extraction;

import generadorDescriptores.database.DatabaseResult;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;

import com.project.frba.bi.BiUtil;
import com.project.frba.bi.descriptor.Descriptor;
import com.project.frba.bi.transformation.Processor;
import com.project.frba.bi.transformation.ProcessorImpl;
import com.project.frba.bi.transformation.TransformationResult;

public class TransformationResultExtractor implements ResultSetExtractor {
	
	private Descriptor descriptor;
	
	public TransformationResultExtractor(Descriptor descriptor) {
		this.descriptor = descriptor;
	}
	
	@Override
	public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
		DatabaseResult result = new DatabaseResult(rs);
		
		Long start = BiUtil.getActualSeconds();
		Processor processor = new ProcessorImpl(descriptor);
		processor.process(result);
		TransformationResult tResult = processor.getTransformationResult();
		Long end = BiUtil.getActualSeconds();
		System.out.println("Duracion transformation: " + (end-start));
		return tResult;
		
	}

	
}
